home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / e / capus2.lha / capus2 / WhatView / Sources / WhatConf.e < prev    next >
Encoding:
Text File  |  1995-03-27  |  8.7 KB  |  279 lines

  1. /*======<<< Peps Header >>>======
  2.  PRGVERSION '0'
  3.  ================================
  4.  PRGREVISION '01'
  5.  ================================
  6.  AUTHOR      'NasGûl'
  7.  ===============================*/
  8. /*======<<<   History   >>>======
  9.  - Convertit les fichiers prefs de whatview,
  10.    D'Ascii en binaire et vice-vers-ça.
  11.  
  12.  ===============================*/
  13.  
  14.  
  15. MODULE 'dos/dos'
  16. MODULE 'dos/rdargs'
  17. MODULE 'dos/dosextens'
  18. MODULE 'exec/lists','exec/nodes'
  19. MODULE 'wvprefs'
  20.  
  21.  
  22. PMODULE 'WhatConfList'
  23.  
  24. DEF mylist:PTR TO lh
  25. DEF testlist:PTR TO lh
  26. DEF defact=-1
  27. /*"main()"*/
  28. PROC main()
  29.     DEF rdargs=NIL,myargs:PTR TO LONG
  30.     myargs:=[0,0,0]
  31.     VOID {banner}
  32.     IF rdargs:=ReadArgs('Source,Destination,SaveBin/S',myargs,NIL)
  33.         mylist:=p_InitList()
  34.         testlist:=p_InitList()
  35.         IF myargs[2]
  36.             WriteF('Read Ascii file..\n')
  37.             p_ReadAsciiFile(myargs[0])
  38.             WriteF('Save Binary file..\n')
  39.             p_SaveBinFile(mylist,myargs[1])
  40.             JUMP end
  41.         ELSE
  42.             WriteF('Read Binary file..\n')
  43.             p_ReadBinFile(myargs[0])
  44.             WriteF('Save Ascii file..\n')
  45.             p_SaveAsciiFile(mylist,myargs[1])
  46.             JUMP end
  47.         ENDIF
  48.         end:
  49.         IF rdargs THEN FreeArgs(rdargs)
  50.     ELSE
  51.         WriteF('Bad args!\n')
  52.     ENDIF
  53. ENDPROC
  54. /**/
  55.  
  56. /*"p_SaveBinFile(list:PTR TO lh,fichier)"*/
  57. PROC p_SaveBinFile(list:PTR TO lh,fichier)
  58.     DEF sactnode:PTR TO actionnode
  59.     DEF node:PTR TO ln
  60.     DEF h
  61.     IF h:=Open(fichier,1006)
  62.         Write(h,[ID_WVPR]:LONG,4)
  63.         sactnode:=list.head
  64.         WHILE sactnode
  65.             node:=sactnode
  66.             IF node.succ<>0
  67.                 Write(h,[ID_WVAC]:LONG,4)
  68.                 Write(h,[sactnode.exectype]:INT,2)
  69.                 Write(h,[sactnode.stack]:LONG,4)
  70.                 Write(h,[sactnode.priority]:INT,2)
  71.                 Write(h,[sactnode.usesubtype]:INT,2)
  72.                 Write(h,node.name,EstrLen(node.name))
  73.                 IF Even(EstrLen(node.name))
  74.                     Out(h,0)
  75.                     Out(h,0)
  76.                 ELSE
  77.                     Out(h,0)
  78.                 ENDIF
  79.                 Write(h,sactnode.command,EstrLen(sactnode.command))
  80.                 IF Even(EstrLen(sactnode.command))
  81.                     Out(h,0)
  82.                     Out(h,0)
  83.                 ELSE
  84.                     Out(h,0)
  85.                 ENDIF
  86.                 Write(h,sactnode.currentdir,EstrLen(sactnode.currentdir))
  87.                 IF Even(EstrLen(sactnode.currentdir))
  88.                     Out(h,0)
  89.                     Out(h,0)
  90.                 ELSE
  91.                     Out(h,0)
  92.                 ENDIF
  93.             ENDIF
  94.             sactnode:=node.succ
  95.         ENDWHILE
  96.         Write(h,[ID_DEFA]:LONG,4)
  97.         Write(h,[defact]:LONG,4)
  98.         IF h THEN Close(h)
  99.     ENDIF
  100. ENDPROC
  101. /**/
  102. /*"p_ReadBinFile(source)"*/
  103. PROC p_ReadBinFile(source)
  104.     DEF len,a,adr,buf,handle,flen=TRUE,pos:PTR TO CHAR
  105.     DEF chunk
  106.     DEF pv[256]:STRING
  107.     DEF node:PTR TO ln
  108.     DEF addact:PTR TO actionnode
  109.     DEF nn=NIL
  110.     IF (flen:=FileLength(source))=-1 THEN RETURN FALSE
  111.     IF (buf:=New(flen+1))=NIL THEN RETURN FALSE
  112.     IF (handle:=Open(source,1005))=NIL THEN RETURN FALSE
  113.     len:=Read(handle,buf,flen)
  114.     Close(handle)
  115.     IF len<1 THEN RETURN FALSE
  116.     adr:=buf
  117.     chunk:=Long(adr)
  118.     IF chunk<>ID_WVPR
  119.         Dispose(buf)
  120.         RETURN FALSE
  121.     ENDIF
  122.     FOR a:=0 TO len-1
  123.         pos:=adr++
  124.         IF Even(pos)
  125.             chunk:=Long(pos)
  126.             SELECT chunk
  127.                 CASE ID_WVAC
  128.                     pos:=pos+4
  129.                     node:=New(SIZEOF ln)
  130.                     addact:=New(SIZEOF actionnode)
  131.                     addact.exectype:=Int(pos)
  132.                     addact.stack:=Long(pos+2)
  133.                     addact.priority:=Int(pos+6)
  134.                     addact.usesubtype:=Int(pos+8)
  135.                     StringF(pv,'\s',pos+10)
  136.                     node.name:=String(EstrLen(pv))
  137.                     node.succ:=0
  138.                     StrCopy(node.name,pv,ALL)
  139.                     IF Even(EstrLen(pv))
  140.                         pos:=pos+10+EstrLen(pv)+2
  141.                     ELSE
  142.                         pos:=pos+10+EstrLen(pv)+1
  143.                     ENDIF
  144.                     StringF(pv,'\s',pos)
  145.                     addact.command:=String(EstrLen(pv))
  146.                     StrCopy(addact.command,pv,ALL)
  147.                     IF Even(EstrLen(pv))
  148.                         pos:=pos+EstrLen(pv)+2
  149.                     ELSE
  150.                         pos:=pos+EstrLen(pv)+1
  151.                     ENDIF
  152.                     StringF(pv,'\s',pos)
  153.                     addact.currentdir:=String(EstrLen(pv))
  154.                     StrCopy(addact.currentdir,pv,ALL)
  155.                     IF Even(EstrLen(pv))
  156.                         pos:=pos+EstrLen(pv)+2
  157.                     ELSE
  158.                         pos:=pos+EstrLen(pv)+1
  159.                     ENDIF
  160.                     nn:=p_AjouteNode(mylist,node.name,addact)
  161.                     IF node THEN Dispose(node)
  162.                 CASE ID_DEFA
  163.                     pos:=pos+4
  164.                     defact:=Long(pos)
  165.             ENDSELECT
  166.         ENDIF
  167.     ENDFOR
  168.     Dispose(buf)
  169.     RETURN TRUE
  170. ENDPROC
  171. /**/
  172.  
  173.  
  174. /*"p_SaveAsciiFile(list:PTR TO lh,fichier)"*/
  175. PROC p_SaveAsciiFile(list:PTR TO lh,fichier)
  176.     DEF sactnode:PTR TO actionnode
  177.     DEF node:PTR TO ln
  178.     DEF h,us
  179.     DEF outstr[256]:STRING
  180.     IF h:=Open(fichier,1006)
  181.         sactnode:=list.head
  182.         WHILE sactnode
  183.             node:=sactnode
  184.             IF node.succ<>0
  185.                 us:=sactnode.usesubtype
  186.                 StringF(outstr,'Type "\s" Com "\s" Dir "\s" Mode "\d" Pri "\d" Stack "\d" \s\n',
  187.                                 node.name,sactnode.command,sactnode.currentdir,
  188.                                 sactnode.exectype,sactnode.priority,sactnode.stack,
  189.                                 IF us<>FALSE THEN 'UseParent' ELSE '')
  190.                 Write(h,outstr,EstrLen(outstr))
  191.             ENDIF
  192.             sactnode:=node.succ
  193.         ENDWHILE
  194.         IF h THEN Close(h)
  195.     ENDIF
  196. ENDPROC
  197. /**/
  198. /*"p_ReadAsciiFile(str)"*/
  199. PROC p_ReadAsciiFile(str)
  200.     DEF fh,buf[1000]:ARRAY,numline=1
  201.     DEF nom[256]:STRING,rn[256]:STRING
  202.     DEF m:PTR TO LONG
  203.     DEF test
  204.     DEF addact:PTR TO actionnode,nn
  205.     DEF str_name[80]:STRING,str_com[80]:STRING,str_dir[256]:STRING
  206.     DEF mode,pri,st,usep
  207.     IF fh:=Open(str,OLDFILE)
  208.         WHILE test:=Fgets(fh,buf,1000)
  209.                 StringF(nom,'\s',test)
  210.                 StrCopy(rn,test,(EstrLen(test)-1))
  211.                 m:=[0,0,0,0,0,0,0]
  212.                 IF getArg(rn,'Type/K,Com/K,Dir/K,Mode/K/N,Pri/K/N,Stack/K/N,UseParent/S',m)
  213.                     /*
  214.                     WriteF('Type :\s Com:\s Dir:\s Mode:\d Pri:\d Stack:\d UseParent:\d\n',
  215.                             m[0],m[1],m[2],Long(m[3]),Long(m[4]),Long(m[5]),Long(m[6]))
  216.                     */
  217.                     StringF(str_name,'\s',m[0])
  218.                     StringF(str_com,'\s',m[1])
  219.                     StringF(str_dir,'\s',m[2])
  220.                     mode:=Long(m[3])
  221.                     pri:=Long(m[4])
  222.                     st:=Long(m[5])
  223.                     usep:=m[6]
  224.                     /*===========================*/
  225.                     /*===========================*/
  226.                     addact:=New(SIZEOF actionnode)
  227.                     addact.exectype:=mode
  228.                     addact.stack:=st
  229.                     addact.priority:=pri
  230.                     IF usep THEN addact.usesubtype:=TRUE ELSE addact.usesubtype:=FALSE
  231.                     addact.command:=String(EstrLen(str_com))
  232.                     StrCopy(addact.command,str_com,ALL)
  233.                     addact.currentdir:=String(EstrLen(str_dir))
  234.                     StrCopy(addact.currentdir,str_dir,ALL)
  235.                     /*===============================*/
  236.                     /*===============================*/
  237.                     p_AjouteNode(testlist,str_name,0)
  238.                     nn:=p_AjouteNode(mylist,str_name,addact)
  239.                 ELSE
  240.                     WriteF('Error in line \d\n',numline)
  241.                     JUMP fin
  242.                 ENDIF
  243.                 m[0]:=0;m[1]:=0;m[2]:=0;m[3]:=0;m[4]:=0;m[5]:=0;m[6]:=0
  244.                 numline:=numline+1
  245.         ENDWHILE
  246.         fin:
  247.         Close(fh)
  248.     ENDIF
  249. ENDPROC
  250. /**/
  251.  
  252. /*"getArg(argu,temp,a:PTR TO LONG)"*/
  253. PROC getArg(argu,temp,a:PTR TO LONG)
  254.     DEF myc:PTR TO csource
  255.     DEF ma:PTR TO rdargs
  256.     DEF rdarg=NIL
  257.     DEF argstr[256]:STRING
  258.     DEF ret=NIL
  259.     StrCopy(argstr,argu,ALL)
  260.     StrAdd(argstr,'\n',1)
  261.     IF ma:=AllocDosObject(DOS_RDARGS,NIL)
  262.         myc:=New(SIZEOF csource)
  263.         myc.buffer:=argstr
  264.         myc.length:=EstrLen(argstr)
  265.         ma.flags:=4
  266.         CopyMem(myc,ma.source,SIZEOF csource)
  267.         IF rdarg:=ReadArgs(temp,a,ma)
  268.             ret:=a
  269.             IF rdarg THEN FreeArgs(rdarg)
  270.         ELSE
  271.         ENDIF
  272.         FreeDosObject(DOS_RDARGS,ma)
  273.     ELSE
  274.         WriteF('AllocDosObject failed !!\n')
  275.     ENDIF
  276.     RETURN ret
  277. ENDPROC
  278. /**/
  279.